﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Equation.Enterprise.Utilities.Caching
{
    public interface ICacheService
    {
        /// <summary>
        /// Retrieve an item from cache.
        /// If item isn't in cache, get if from call back function then return it.
        /// Do not serialize item to disc.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheId">Key in cache of item (case insensitive)</param>
        /// <param name="getItemCallBack">Call back function to call in case item isn't in cache. Usually repository method</param>
        /// <param name="cacheDurationMinutes">Number of minutes to keep item in cache</param>
        /// <returns></returns>
        T Get<T>(string cacheId, Func<T> getItemCallBack, int cacheDurationMinutes) where T : class;

        /// <summary>
        /// Retrieve an item from cache.
        /// If item isn't in cache, get if from call back function then return it.
        /// Caller specifies whether or not to serialize item to disc.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheId">Key in cache of item (case insensitive)</param>
        /// <param name="getItemCallBack">Call back function to call in case item isn't in cache. Usually repository method</param>
        /// <param name="cacheDurationMinutes">Number of minutes to keep item in cache</param>
        /// <param name="withSerialization">Whether or not to serialize item to disc</param>
        /// <returns></returns>
        T Get<T>(string cacheId, Func<T> getItemCallBack, int cacheDurationMinutes, bool withSerialization)
            where T : class;

        /// <summary>
        /// Retrieve an item from cache.
        /// If item isn't in cache, return null.
        /// Independtly check for expiration for the cacheId (case insensitive). If expired, get it from call back function in an asynch call and populate cache in background.
        /// This method will not wait for call back function to finish before returning.
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheId"></param>
        /// <param name="getItemCallBack"></param>
        /// <param name="cacheDurationMinutes"></param>
        /// <param name="withSerialization"></param>
        /// <returns></returns>
        T GetAsynch<T>(string cacheId, Func<T> getItemCallBack, int cacheDurationMinutes, bool withSerialization)
            where T : class;
    }
}
